package com.home766.service.impl;

import com.home766.dao.SchemeDao;
import com.home766.entity.Scheme;
import com.home766.service.SchemeService;
import net.biz.Page;
import net.biz.Pageable;
import net.biz.service.impl.BaseServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;

/**
 * 方案-serviceImpl
 */
@Service("schemeServiceImpl")
public class SchemeServiceImpl extends BaseServiceImpl<Scheme, Long> implements SchemeService{
	
	@Resource(name="schemeDaoImpl")
	public void setBaseDao(SchemeDao schemeDao) {
		super.setBaseDao(schemeDao);
	}
	
	@Resource(name="schemeDaoImpl")
	private SchemeDao schemeDao;
	
	/**
	 * 检查名称是否存在
	 * @param name
	 * @return
	 */
	@Override
	public boolean checkExists(String name) {
		return schemeDao.checkExists(name);
	}
	
	/**
	 * 方案列表分页查询(带查询条件)
	 * @param pageable
	 * @param sn            方案编码
	 * @param name          方案名称
	 * @param createPerson  创建人
	 * @param createDate    创建时间
	 * @param type          方案类型
	 * @param isMarketable  是否已上架
	 * @return
	 */
	@Override
	public Page<Scheme> findPage(Pageable pageable, String sn, String name, String createPerson, Date beginDate, Date endDate, Long type, Boolean isMarketable, Boolean isTehui){
		return schemeDao.findPage(pageable, sn, name, createPerson,beginDate,endDate, type, isMarketable,isTehui);
	}
	
	/**
	 * 前台方案列表数据查看
	 * @param pageable
	 * @param acreage
	 * @param attribute
	 * @param brandId
	 * @return
	 */
	@Override
	public Page<Scheme> findPage(Pageable pageable, Integer acreage, Integer attribute, Long brandId, Long auxiliaryId, Boolean isTehui, Long type) {
		return schemeDao.findPage(pageable,acreage,attribute,brandId,auxiliaryId,isTehui,type);
	}
	
	/**
	 * 方案逻辑删除
	 */
	@Transactional
	@Override
	public void delete(Long... ids) {
		if (ids != null) {
			for (Long id : ids) {
				Scheme sp = schemeDao.find(id);
				if(sp != null){
					//设置为删除状态
					sp.setIsDelete(true);
					super.update(sp);
				}
			}
		}
	}
	@Override
	public void updateUpDown() {
		schemeDao.updateUpDown();
	}
}
